package com.leo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleMapProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
import javafx.stage.Stage;

/**
 * @ClassName MapPropertyDemo
 * @Description
 * @Author wangss
 * @date 2020.05.28 23:06
 * @Version 1.0
 */
public class MapPropertyDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        ObservableMap<String, String> map = FXCollections.observableHashMap();
        map.put("1", "A");
        map.put("2", "B");
        map.put("3", "C");
        map.put("4", "D");

        SimpleMapProperty mapProperty = new SimpleMapProperty(map);

        mapProperty.addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                System.out.println(newValue);
            }
        });

        mapProperty.addListener(new MapChangeListener() {
            @Override
            public void onChanged(Change change) {
                System.out.println(change.getKey());
            }
        });

        mapProperty.put("5", "E");

        Platform.exit();
    }
}
